﻿using System;
using System.Collections.Generic;
using NHibernate;
using Model;

namespace Infrastructure
{

    public abstract class BaseRepository<T> : IRepository<T>
    {
        private ISession context;

        public BaseRepository(ISession session)
        {
            context = session;
        }

        public void Save(T obj)
        {
                context.SaveOrUpdate(obj);
        }

        public void Add(T obj)
        {
                context.Save(obj);
        }

        public T FindBy(Guid id)
        {
            return context.Get<T>(id);
        }

        public List<T> FindAll()
        {
            ICriteria CriteriaQuery = context.CreateCriteria(typeof(T));
            return (List<T>)CriteriaQuery.List<T>();
        }
    }
}
